"""Auth serve configuration"""
from dataclasses import dataclass

from dbgpt.core.awel.flow import (
    TAGS_ORDER_HIGH,
    ResourceCategory,
    auto_register_resource,
)
from dbgpt.util.i18n_utils import _
from dbgpt_serve.core import BaseServeConfig

APP_NAME = "auth"
SERVE_APP_NAME = "dbgpt_serve_auth"
SERVE_APP_NAME_HUMP = "dbgpt_serve_Auth"
SERVE_CONFIG_KEY_PREFIX = "dbgpt.serve.auth."
SERVE_SERVICE_COMPONENT_NAME = f"{SERVE_APP_NAME}_service"

# User table
SERVER_USER_TABLE_NAME = "sys_user"
# Role table
SERVER_ROLE_TABLE_NAME = "sys_role"
# User-Role relationship table
SERVER_USER_ROLE_TABLE_NAME = "sys_user_role"
# Menu table
SERVER_MENU_TABLE_NAME = "sys_menu"
# Role-Menu relationship table
SERVER_ROLE_MENU_TABLE_NAME = "sys_role_menu"
# Data permission table
SERVER_DATA_PERMISSION_TABLE_NAME = "sys_data_permission"
# Login log table
SERVER_LOGIN_LOG_TABLE_NAME = "sys_login_log"
# Operation log table
SERVER_OPERATION_LOG_TABLE_NAME = "sys_operation_log"


@auto_register_resource(
    label=_("Auth Serve Configurations"),
    category=ResourceCategory.COMMON,
    tags={"order": TAGS_ORDER_HIGH},
    description=_("This configuration is for the auth serve module."),
    show_in_ui=False,
)
@dataclass
class ServeConfig(BaseServeConfig):
    """Auth serve configuration"""

    __type__ = APP_NAME

    # JWT configuration
    jwt_secret_key: str = "dbgpt-secret-key-change-me-in-production"
    jwt_algorithm: str = "HS256"
    jwt_expire_minutes: int = 60 * 24 * 7  # 7 days

    # Password encryption
    password_hash_rounds: int = 12
